<template>
  <div class="contents">

    <el-dialog
      title="新增仓库"
      :visible.sync="dialogstoreadd"
      :close-on-click-modal=false
      :destroy-on-close=true
      width="30%"
      >
      <div>
        <label>
          仓库名称
          <el-input style="margin-top: 10px;" v-model="storeadd.name" placeholder="请输入内容"></el-input>
        </label>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogstoreadd = false">取 消</el-button>
        <el-button type="primary" @click="addstorefunc">确 定</el-button>
      </span>
    </el-dialog>


     <el-dialog
       title="编辑仓库"
       :visible.sync="dialogstoreedit"
       :close-on-click-modal=false
       :destroy-on-close=true
       width="30%"
       >
       <div>
         <label>
           <div>仓库名称</div>
           <el-input style="margin-top: 10px;" v-model="storeedit.name" placeholder="请输入内容"></el-input>
         </label>
       </div>
       <span slot="footer" class="dialog-footer">
         <el-button @click="dialogstoreedit = false">取 消</el-button>
         <el-button type="primary" @click="editstorefunc">确 定</el-button>
       </span>
     </el-dialog>




    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="仓库设置" name="first">
        <div class="btn-fixed">
          <el-button>属地仓库管理</el-button>
          <el-button type="primary" @click="addstore">新增</el-button>
        </div>
        <el-table
          :data="table1.list"
          style="width: 100%;"
          v-loading="listLoading"
        >
          <el-table-column label="序号" type="index"></el-table-column>
          <el-table-column prop="name" label="仓库名称"></el-table-column>
          <el-table-column prop="no" label="仓库编码"></el-table-column>
          <el-table-column prop="createtime" label="创建时间"></el-table-column>
          <el-table-column prop="aa" label="" width="100px">
            <template slot-scope="scope">
              <div style="text-align: center;">
                <el-link :underline="false" @click="editstore(scope.row)" type="primary">编辑</el-link>
<el-popconfirm
  title="确定删除吗？"
  @confirm = delstorefunc(scope.row)
>
                <el-link slot="reference" style="margin-left: 10px;" :underline="false" type="primary">删除</el-link>
</el-popconfirm>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          background
          layout="total, prev, pager, next,sizes, jumper"
          :page-size="table1.pageSize"
          :page-sizes="[10, 20, 30, 40]"
          style="text-align: left;"
          :total="table1.size"
        />
      </el-tab-pane>
      <el-tab-pane label="库区设置" name="second">
        <el-select
          v-model="warehouse_id"
          placeholder="请选择"
          @change="getAreaList"
        >
          <el-option
            v-for="(item, index) in table1.list"
            :key="index"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
        <div class="btn-fixed">
          <el-button type="primary" icon="el-icon-plus" @click="areaAdd">
            新增
          </el-button>
        </div>
        <!-- 库区设置弹窗 -->
        <el-dialog
          :title="areatitle"
          :visible.sync="dialogArea"
          :close-on-click-modal="false"
          width="40%"
        >
          <el-form ref="addForm" :model="formAreaData" label-width="80px">
            <el-form-item prop="warehouse_id" label="仓库名称:">
              <el-select
                v-model="formAreaData.warehouse_id"
                placeholder="请选择"
                style="width: 100%;"
                :disabled="areashow"
              >
                <el-option
                  v-for="(item, index) in table1.list"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item prop="area_name" label="库区名称:">
              <el-input
                v-model="formAreaData.area_name"
                placeholder="请输入库区名称"
                maxlength="128"
                show-word-limit
              ></el-input>
            </el-form-item>
            <el-form-item prop="code" label="库区编码:">
              <el-input
                v-model="formAreaData.code"
                placeholder="请输入库区编码"
                maxlength="128"
                show-word-limit
              ></el-input>
            </el-form-item>
            <el-form-item prop="remarks" label="说明:">
              <el-input
                v-model="formAreaData.remarks"
                placeholder="请输入库区说明"
                type="textarea"
                maxlength="200"
                show-word-limit
              ></el-input>
            </el-form-item>
          </el-form>
          <span slot="footer" class="dialog-footer">
            <el-button @click="dialogArea = false">取 消</el-button>
            <el-button v-if="areashow" type="primary" @click="AreaEdit">
              保存
            </el-button>
            <span v-else style="margin-left: 10px;">
              <el-button type="primary" @click="handleArea('close')">
                保存
              </el-button>
              <el-button type="primary" @click="handleArea">
                保存并新增
              </el-button>
            </span>
          </span>
        </el-dialog>
        <el-table
          :data="table2.list"
          @cell-mouse-enter="enter"
          @cell-mouse-leave="leave"
          v-loading="listLoading"
          style="width: 100%; margin-top: 10px;"
        >
          <el-table-column label="序号" type="index"></el-table-column>
          <el-table-column
            prop="warehouseInfo.name"
            label="仓库名称"
          ></el-table-column>
          <el-table-column prop="code" label="库区编码"></el-table-column>
          <el-table-column prop="area_name" label="库区名称"></el-table-column>
          <el-table-column prop="remarks" label="说明"></el-table-column>
          <el-table-column width="100px">
            <template slot-scope="scope">
              <div v-show="scope.row.id === isshow" class="el-butotn-div">
                <div class="area-layout">
                  <span @click="handleAreaEdit(scope.row)">编辑</span>
                  <span @click="handleAreaDel(scope.row)">删除</span>
                </div>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          background
          layout="total, prev, pager, next,sizes, jumper"
          :page-size="table2.pageSize"
          :page-sizes="[10, 20, 30, 40]"
          style="text-align: left;"
          :total="table2.size"
        />
      </el-tab-pane>
      <el-tab-pane label="库位设置" name="third">
        <el-row :gutter="10">
          <el-col :span="3" style="height: 182px;">
            <el-select
              v-model="warehouseId"
              placeholder="请选择"
              @change="handleSpace"
            >
              <el-option
                v-for="(item, index) in table1.list"
                :key="index"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
            <div class="storeMenu">
              <div class="titles">
                {{ table1.list[warehouseId - 1].name }}
              </div>
              <div v-for="(item, index) in wareData" :key="index">
                <div
                  class="areaMenu"
                  :class="{ active: index == cnum }"
                  @click="checkArea(item, index)"
                >
                  {{ item.area_name }}
                </div>
              </div>
            </div>
          </el-col>
          <el-col :span="21">
            <el-row>
              <el-col :span="5">
                <el-input placeholder="输入库位名称">
                  <el-button slot="append" icon="el-icon-search"></el-button>
                </el-input>
              </el-col>
            </el-row>
            <div class="btn-fixed">
              <el-button disabled>批量删除</el-button>
              <el-button>生成库位</el-button>
              <el-button icon="el-icon-plus" @click="spaceAdd">新增</el-button>
            </div>
            <!-- 库位设置弹窗 -->
            <el-dialog
              :title="spacetitle"
              :visible.sync="dialogSpace"
              :close-on-click-modal="false"
              width="40%"
            >
              <el-form ref="addForm" :model="formSpaceData" label-width="80px">
                <el-form-item prop="space_name" label="库位名称:">
                  <el-input
                    v-model="formSpaceData.space_name"
                    placeholder="请输入库位名称"
                  ></el-input>
                </el-form-item>
                <el-form-item prop="status" label="是否启用:">
                  <el-radio-group v-model="formSpaceData.status">
                    <el-radio :label="1">启用</el-radio>
                    <el-radio :label="2">未启用</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-form>
              <span slot="footer" class="dialog-footer">
                <el-button @click="dialogSpace = false">取 消</el-button>
                <el-button v-if="spaceshow" type="primary" @click="SpaceEdit">
                  保存
                </el-button>
                <span v-else style="margin-left: 10px;">
                  <el-button type="primary" @click="handleSpaceAdd('close')">
                    保存
                  </el-button>
                  <el-button type="primary" @click="handleSpaceAdd">
                    保存并新增
                  </el-button>
                </span>
              </span>
            </el-dialog>
            <el-table
              :data="table3.list"
              @cell-mouse-enter="enter"
              @cell-mouse-leave="leave"
              style="width: 100%; margin-top: 10px;"
            >
              <el-table-column
                type="selection"
                width="55"
                align="center"
              ></el-table-column>
              <el-table-column label="序号" type="index"></el-table-column>
              <el-table-column
                prop="space_name"
                label="库位名称"
              ></el-table-column>
              <el-table-column prop="status" label="库位状态"></el-table-column>
              <el-table-column
                prop="inventoryStatus"
                label="库存状态"
              ></el-table-column>
              <el-table-column
                prop="createtime"
                label="创建时间"
              ></el-table-column>
              <el-table-column width="100px">
                <template slot-scope="scope">
                  <div v-show="scope.row.id === isshow" class="el-butotn-div">
                    <div class="area-layout">
                      <span @click="handleSpaceEdit(scope.row)">编辑</span>
                      <span @click="handleSpaceDel(scope.row)">删除</span>
                    </div>
                  </div>
                </template>
              </el-table-column>
            </el-table>
            <el-pagination
              background
              layout="total, prev, pager, next,sizes, jumper"
              :page-size="table3.pageSize"
              :page-sizes="[10, 20, 30, 40]"
              style="text-align: left;"
              :total="table3.size"
            />
          </el-col>
        </el-row>
      </el-tab-pane>
      <el-tab-pane label="默认商品库位" name="fourth">
        <el-row :gutter="10" type="flex">
          <el-col :span="4">
            <el-select v-model="deData.warehouse_id" placeholder="请选择">
              <el-option
                v-for="(item, index) in table1.list"
                :key="index"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-col>
          <el-col :span="4">
            <goods-type @selectType="changeType"></goods-type>
          </el-col>
          <el-col :span="8">
            <el-input
              v-model="deData.code"
              placeholder="请选商品名/助记码/编码/别名/关键字"
            ></el-input>
          </el-col>
          <el-col :span="4">
            <el-input v-model="deData.spaceName" placeholder="输入库位名称">
              <el-button slot="append" icon="el-icon-search"></el-button>
            </el-input>
          </el-col>
        </el-row>
        <div class="btn-fixed">
          <el-button @click="dialogimport = true">导入库位</el-button>
          <el-button @click="lookspaceatate()">查看库位状态</el-button>
          <!-- dialogSpaceatate = true -->
        </div>
        <!-- 库位导入弹窗 -->
        <el-dialog
          title="库位导入"
          :close-on-click-modal="false"
          :visible.sync="dialogimport"
          width="60%"
        >
          <div class="importDes">
            <p>导入说明：</p>
            <p>
              1.
              <span style="color: red;">*</span>
              标识的字段导入模板中必须包含对应的列，非必要字段导入模板中可没有对应列。
            </p>
            <p>
              2.
              导入时表格中的商品、仓库、库区、库位必须是系统存在的数据，否则导入失败。
            </p>
            <p>
              3.
              库位导入是更新操作，不论商品原来是否有库位则进行覆盖，导入成功后，商品建立与库位的绑定关系。
            </p>
            <p>
              4. 导入文件仅支持xlsx格式，大小不超过2M，数据不超过2000行。
            </p>
            <p>
              5. 导入文件不能包含“合并单元格”，否则无法导入。
            </p>
            <p>
              5. 导入时只要有一行数据不正确，则导入失败。
            </p>
            <p style="color: #00a54f;">
              上传文件名：
            </p>
            <div style="display: flex;">
              <el-upload
                action="https://jsonplaceholder.typicode.com/posts/"
                style="margin-right: 10px;"
              >
                <el-button size="small" type="primary">导入库位</el-button>
              </el-upload>
              <el-upload action="https://jsonplaceholder.typicode.com/posts/">
                <el-button size="small" icon="el-icon-download">
                  下载模板
                </el-button>
              </el-upload>
            </div>
          </div>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogimport = false">取 消</el-button>
          </div>
        </el-dialog>
        <!-- 库位状态弹窗 -->
        <el-dialog
          title="查看库位状态"
          :close-on-click-modal="false"
          :visible.sync="dialogSpaceatate"
        >
          <el-form :inline="true" :model="formstate">
            <el-form-item>
              <el-select v-model="formstate.state" placeholder="请选择库位">
                <el-option label="全部库位" value="0"></el-option>
                <el-option label="可用库位" value="1"></el-option>
                <el-option label="占用库位" value="2"></el-option>
                <el-option label="重复库位" value="3"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-input
                placeholder="输入库位名称"
                v-model="formstate.space_name"
              >
                <el-button slot="append" icon="el-icon-search"></el-button>
              </el-input>
            </el-form-item>
          </el-form>
          <el-table :data="gridData">
            <el-table-column label="序号" type="index"></el-table-column>
            <el-table-column label="库位" width="150"></el-table-column>
            <el-table-column label="创建时间" width="200"></el-table-column>
            <el-table-column property="address" label="状态"></el-table-column>
          </el-table>
          <el-pagination
            background
            layout="total, prev, pager, next,sizes, jumper"
            :page-size="10"
            :page-sizes="[10, 20, 30, 40]"
            style="text-align: left;"
            :total="0"
          />
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogSpaceatate = false">关 闭</el-button>
          </div>
        </el-dialog>
        <el-table
          :data="table4.list"
          @cell-mouse-enter="enter"
          @cell-mouse-leave="leave"
          v-loading="listLoading"
          style="width: 100%; margin-top: 10px;"
        >
          <el-table-column label="序号" type="index"></el-table-column>
          <el-table-column
            prop="code"
            label="商品编码"
          ></el-table-column>
          <el-table-column prop="category.name" label="商品分类"></el-table-column>
          <el-table-column
            prop="name"
            label="商品名称"
          ></el-table-column>
          <el-table-column  label="数量"></el-table-column>
          <el-table-column prop="unit" label="单位"></el-table-column>
          <el-table-column prop="warehouseInfo.name" label="仓库名称"></el-table-column>
          <el-table-column
            prop="warehouseArea.area_name"
            label="库区"
          ></el-table-column>



          <el-table-column prop="warehouseSpace.space_name" label="库位">
            <template slot-scope="scope">
              {{scope.row.warehouseSpace.space_name}}
              <div  @click="storagelocationedit(scope.row)" v-show="scope.row.id === isshow" class="el-butotn-div">
                <div class="div-layout">
                  <span>编辑库位</span>
                </div>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          background
          layout="total, prev, pager, next,sizes, jumper"
          :page-size="deDatapage.pageSize"
          :current-page="deDatapage.current"
          @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
          :page-sizes="[10, 20, 30, 40]"
          style="text-align: left;"
          :total="table4.total"
        />
      </el-tab-pane>
    </el-tabs>
    <el-dialog
      title="编辑库位"
      :visible.sync="storagelocation"
      width="500px"
      center>
      <span style="margin-right: 30px;margin-left: 30px;">库位名称</span>
      <span><el-cascader
    v-model="storagelocationid"
    :options="options"
    :props="{ expandTrigger: 'hover' }"
    ></el-cascader></span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="storagelocation = false">取 消</el-button>
        <el-button type="primary" @click="storagelocationaffirm()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import {
    getWarehouseQuery,
    getWarehouseAreaQuery,
    getWarehouseAreaAdd,
    getWarehouseAreaEdit,
    getWarehouseAreaDel,
    WarehousePlaceQuery,
    WarehousePlaceAdd,
    WarehousePlaceDel,
    WarehousePlaceEdit,
    WarehouseInfo,
    Warehouseadd,
    Warehouseedit,
    Warehousedel,
	WarehouseareaqueryArea,
  } from '@/api/warehouse'
  // WarehouseInfo
  import {getGoodsEdit} from '@/api/goodslist'
  import goodsType from '@/components/goodsType.vue'
  export default {
    components: {
      goodsType,
    },
    watch:{
      deData:{
        handler(val,oldval){
          console.log(val)
          this.getGoodsInfo()
        },
        deep:true
      }
    },
    data() {
      return {
        activeName: 'first',
        listLoading: true,
        dialogstoreadd:false,
        dialogstoreedit:false,
        table1: {
          list: [
            {
              name: '',
            },
          ],
        },
        storeadd:{
         "wsId": 1,
         "name": "",
         "cuser": "tom",
        "uuser": "tom",
        },
        storeedit:{
         "id":"",
         "wsId": 1,
         "name": "",
         "cuser": "tom",
        "uuser": "tom",
        },
        storagelocationeditrow:"",
        storagelocation:false, //库位弹窗
        table2: [],
        warehouse_id: 1,
        areashow: false,
        dialogArea: false,
        areatitle: '新增库区',
        formAreaData: {
          warehouse_id: 1,
          code: '',
          area_name: '',
          remarks: '',
          cuser: 'demoData',
          ctime: 0,
          uuser: 'demoData',
          utime: 0,
        },
        storagelocationid:"",
        table3: [],
        warehouseId: 1,
        options:[],
        cnum: 0,
        spacetitle: '新增库位',
        formSpaceData: {
          space_name: '',
          status: '',
          inventoryStatus: 1,
          areaId: '',
          warehouseId: '',
          cuser: 'demoData',
          ctime: 0,
          uuser: 'demoData',
          utime: 0,
          remarks: 'demoData',
        },
        spaceshow: false,
        dialogSpace: false,
        wareData: [],

        deData: {
          warehouse_id: 1,
          category_id: '',
          code: '',
          spaceName: '',
        },

        // {
        //     "warehouse_id":2,//仓库id
        //     "spaceName":"" , //库区名
        //      "code":"" ,//商品名，助记名，编码等，
        //      "category_id":""//商品名
        // }
        deDatapage:{
          pagesize:10,
          current:1,
        },
        table4: [],
        dialogimport: false,
        dialogSpaceatate: false,
        formstate: {
          state: "0",
          space_name: '',
        },
        gridData: [],
        isshow: -1,
      }
    },
    created() {
      this.getList()
    },
    methods: {
      handleSizeChange(val) {
        this.deDatapage.size = val
              console.log(`每页 ${val} 条`);
              this.getGoodsInfo()
            },
            handleCurrentChange(val) {
              this.deDatapage.current = val
              this.getGoodsInfo()
              console.log(`当前页: ${val}`);
            },
      editstore(val){
          console.log("编辑",val);
          this.storeedit.id = val.id
          this.storeedit.name = val.name
          this.dialogstoreedit = true
      },
      async editstorefunc(){
        if(this.storeedit.name == ""){
          this.$message.error("请填写所有字段")
        }else{
          let res = await Warehouseedit(this.storeedit)
          if(res.status == 200){
            this.$message.success("修改成功")
            this.getList()
            this.dialogstoreedit = false
          }else{
            this.$message.error("修改失败")
          }
        }
      },
      async delstorefunc(val){
        let data = {
          id:val.id
        }
        let res = await Warehousedel(data)
        if(res.status == 200){
          this.$message.success("删除成功")
          this.getList()
        }else{
          this.$message.error("删除失败")
        }
      }
      ,async addstorefunc(){
        if(this.storeadd.name == ""){
          this.$message.error("请填写所有字段")
        }else{
          let res = await Warehouseadd(this.storeadd)
          if(res.status == 200){
            this.$message.success("添加成功")
            this.getList()
            this.dialogstoreadd = false
            this.storeadd.name = ""
          }else{
            this.$message.error("添加失败")
          }
        }
      },
      addstore(){
        // Warehouseadd
        this.dialogstoreadd = true
      },
      async lookspaceatate(){
        this.dialogSpaceatate = true
      },
      async getList() {
        this.listLoading = true
        const res = await getWarehouseQuery({ wis_id: 1 })
        this.table1 = res.data
        this.listLoading = false
      },async storagelocationedit(val){
        this.storagelocationeditrow = val //储存当前行的信息
        let data = {
          warehouse_id:val.warehouse_id
        }
		    let res = await WarehouseareaqueryArea(data)
        console.log("库位",res);
        let list = []
        res.data.forEach((item)=>{
            let childlist = []
          if(item.warehouseSpaceList.length != 0){
            item.warehouseSpaceList.forEach((r)=>{
              let child = {
                value:r.id,
                label:r.space_name
              }
              childlist.push(child)
            })
          }
          let parmas = {
            value:item.id,
            label:item.area_name,
            children:childlist
          }
          list.push(parmas)
        })
        console.log("list",list);
        // let options = res.data
        this.options = list
        this.storagelocation = true
      },
      async storagelocationaffirm(){
        if(this.storagelocationid != ""){
          this.storagelocation = false
          console.log("最终选择",this.storagelocationid);
          console.log(this.storagelocationeditrow);
          let data = {
            id:this.storagelocationeditrow.id,
            warehouse_id:this.storagelocationeditrow.warehouse_id,
            area_id:this.storagelocationid[0],
            space_id:this.storagelocationid[1]
          }
          let res = await getGoodsEdit(data)
          console.log("resss",res);
          this.getGoodsInfo()
          this.storagelocationid = ""
        }else{
          this.$message.error("请选择后再确认")
        }
      },
      async getAreaList() {
        this.listLoading = true
        const res = await getWarehouseAreaQuery({
          warehouse_id: this.warehouse_id,
        })
        this.table2 = res.data
        this.listLoading = false
      },
      async getPlaceList() {
        this.listLoading = true
        const res = await WarehousePlaceQuery({
          areaId: 1,
        })
        this.table3 = res.data
        this.listLoading = false
      },
      async getGoodsInfo() {
        this.listLoading = true
        const res = await WarehouseInfo(this.deDatapage,this.deData)
        console.log("默认商品库位",res);
        this.table4 = res.data
        this.listLoading = false
      },
      async handleClick(item) {
        if (item.name == 'first') {
          this.getList()
        } else if (item.name == 'second') {
          this.getAreaList()
        } else if (item.name == 'third') {
          // this.getPlaceList()
          // this.checkArea()
          this.handleSpace()
        } else {
          this.getGoodsInfo()
        }
      },
      //库区设置新增
      async handleArea(flag) {
        const res = await getWarehouseAreaAdd(this.formAreaData)
        console.log('新增',res)
        if (res.status) {
          if (flag == 'close') {
            this.$message.success('新增成功')

            this.dialogArea = false
          }
          this.$refs.addForm.resetFields()
          this.getAreaList()
        }
      },
      areaAdd() {
        this.dialogArea = true
        this.areatitle = '新增库区'
        this.$refs.addForm.resetFields()
      },
      //库区设置编辑
      handleAreaEdit(item) {
        this.dialogArea = true
        this.areashow = true
        this.formAreaData = item
        this.areatitle = '编辑库区'
      },
      async AreaEdit() {
        const res = await getWarehouseAreaEdit(this.formAreaData)
        if (res.data) {
          this.dialogArea = false
          this.areashow = false
          this.getAreaList()
          this.$message({
            type: 'success',
            message: '保存成功!',
          })
        }
      },
      //库区设置删除
      async handleAreaDel(item) {
        this.$confirm('您是否确定需要删除该条数据吗？', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(async () => {
          const res = await getWarehouseAreaDel({
            id: item.id,
          })
          console.log('删除',res)
          if (res.status == 200) {
            this.getAreaList()
            this.$message({
              type: 'success',
              message: '删除成功',
            })
          }
        })
      },
      //库位新增
      async handleSpaceAdd(flag) {
        this.formSpaceData.areaId = this.wareData[this.cnum].id
        this.formSpaceData.warehouseId = this.warehouseId
        const res = await WarehousePlaceAdd(this.formSpaceData)
        if (res.status) {
          if (flag == 'close') {
            this.dialogSpace = false
          }
          this.$message.success('新增成功')
          this.$refs.addForm.resetFields()
          this.checkArea(this.wareData[this.cnum], this.cnum)
        }
      },
      spaceAdd() {
        this.dialogSpace = true
        this.spacetitle = '新增库位'
      },
      async handleSpace() {
        const res = await getWarehouseAreaQuery({
          warehouse_id: this.warehouseId,
        })
        this.wareData = res.data.list
        this.checkArea(this.wareData[this.cnum], 0)
      },
      async checkArea(item, index) {
        this.cnum = index
        if (item) {
          const res = await WarehousePlaceQuery({
            areaId: item.id,
          })
          this.table3 = res.data
        } else {
          this.table3 = []
        }
      },
      //库位设置编辑
      handleSpaceEdit(item) {
        this.formSpaceData = item
        this.dialogSpace = true
        this.spaceshow = true
        this.spacetitle = '编辑库位'
      },
      async SpaceEdit() {
        const res = await WarehousePlaceEdit(this.formSpaceData)
        if (res.data) {
          this.dialogSpace = false
          this.spaceshow = false
          this.checkArea(this.wareData[this.cnum], this.cnum)
          this.$message({
            type: 'success',
            message: '保存成功!',
          })
        }
      },
      //库位设置删除
      async handleSpaceDel(item) {
        this.$confirm('您是否确定需要删除该条数据吗？', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(async () => {
          const res = await WarehousePlaceDel({
            id: item.id,
          })
          if (res.status) {
            this.checkArea(this.wareData[this.cnum], 0)
            this.$message({
              type: 'success',
              message: '删除成功',
            })
          }
        })
      },
      changeType(data) {
        this.deData.category_id = data[1]
      },
      enter(row, column, cell) {
        this.isshow = row.id
      },
      leave(row, column, cell) {
        this.isshow = -1
      },
    },
  }
</script>

<style lang="scss" scoped>
  .contents {
    padding: 0 20px 10px;

    .btn-fixed {
      position: fixed;
      top: 133px;
      right: 50px;
      z-index: 12;
    }

    .storeMenu {
      border: 1px solid #f0f2f0;
      border-radius: 1px;
      margin-top: 10px;
      height: calc(100% - 45px);
      width: 100%;
      overflow-y: auto;

      .titles {
        text-align: center;
        background: #f3f5f3;
        line-height: 36px;
        font-weight: 700;
      }

      .areaMenu {
        line-height: 50px;
        padding: 0 15px;
        text-align: left;
        font-size: 14px;
        cursor: pointer;
        border-bottom: 1px solid #f0f2f0;

        &:hover {
          background: #03ac54;
          color: #fff;
        }
      }

      .active {
        background: #03ac54;
        color: #fff;
      }
    }

    .el-butotn-div {
      position: absolute;
      right: 0%;
      top: 0%;
      background: #1890ff;
      color: #fff;
      height: 100%;
      width: 100%;
      padding: 0 10px;

      .area-layout {
        display: flex;
        justify-content: space-between;
        align-items: center;
        vertical-align: middle;
        height: 100%;
        cursor: pointer;
      }

      .div-layout {
        display: flex;
        justify-content: center;
        align-items: center;
        vertical-align: middle;
        height: 100%;
        cursor: pointer;
      }
    }

    .importDes {
      padding: 0 15px 15px;
    }
  }
</style>
